package com.wing.common.utils;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 结果
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Result implements Serializable {

    public enum Code {

        SUCCESS(200, "操作成功"),
        FAIL(500, "操作失败"),
        EXCEPTION(400, "系统繁忙,请稍后再试"),
        AUTH_ERROR(403, "没有访问权限"),
        NO_FOUND_ERROR(404, "请求路径不存在"),
        METHOD_ERROR(405, "请求方法错误"),
        PARAMETER_ERROR(501, "参数错误"),
        LOGIN_ERROR(401, "未登录"),
        LOGIN_EXPIRED(503, "登录过期"),
        PAY_PASSWORD_NOT_SET(601, "支付密码未设置"),
        BAD_CREDENTIALS(1001, "用户名或密码错误"),
        BAD_MOBILE_CODE(1002, "手机号或验证码不正确"),
        ACCOUNT_DISABLED(1003, "账号已禁用"),
        ACCOUNT_EXPIRED(1004, "账号已过期"),
        ACCOUNT_LOCKED(1005, "账号已锁定"),
        CREDENTIALS_EXPIRED(1006, "凭证已过期"),
        ACCESS_DENIED(1007, "不允许访问"),
        PERMISSION_DENIED(1008, "无权限访问"),
        CREDENTIALS_INVALID(1009, "凭证无效或已过期"),
        REFRESH_CREDENTIALS_INVALID(1010, "刷新凭证无效或已过期"),
        INVALID_REQUEST(1011, "无效请求或请求不接受"),
        INVALID_CLIENT(1012, "client_id或client_secret错误"),
        INVALID_SCOPE(1013, "无效的scope"),
        FORBIDDEN_OPERATION(1014, "演示环境禁止修改、删除重要数据"),
        TOKEN_ACCESS_FORBIDDEN(1015, "token已被禁止访问"),
        SYSTEM_ERROR(5000, "系统异常"),
        REQUIRE_REFRESH(501,"请刷新页面"),
        REQUIRE_VERSION_UPDATE(502,"请更新最新的版本"),
        OUT_OF_RANGE_ERROR(601,"超出领取金额范围"),
        NONW_AUTH_ERROR(600,"没有领新权限"),
        OUT_THRESHOLD_ERROR(602,"未归还金额已到达未归还金额阈值");

        private int code;
        private String desc;

        public int getCode() {
            return code;
        }
        public String getDesc() {
            return desc;
        }

        Code(int code, String desc){
            this.code = code;
            this.desc = desc;
        }
    }

    /**
     * 状态码
     *
     * @see Code
     */
    protected int code;

    /**
     * 提示信息
     */
    protected String msg;

    /**
     * 是否成功
     *
     * @param result 结果
     * @return boolean
     */
    public static boolean isSuccess(Result result) {
        return result != null && Code.SUCCESS.getCode() == result.getCode();
    }

}
